<?php
define('IN_MEDIA',true);
include('includes/config.php');
include('includes/functions.php');

if ($_POST['showPost'] && $_POST['media_id']) {
	$id = (int)$_POST['media_id'];
	$sql = "SELECT m_cat FROM ".$tb_prefix."data WHERE m_id = $id";
	$query = $mysql->query($sql);
	if($mysql->num_rows($query)) {
		$row = $mysql->fetch_array($query);
		$catID = $row['m_cat'];
		$title = m_get_data('CAT',$catID);			
	}	
	$sql_random = "SELECT * FROM ".$tb_prefix."data WHERE m_cat = $catID limit 0,10";
	$query_random = $mysql->query($sql_random);
	if($mysql->num_rows($query_random)) {
		while ($r = $mysql->fetch_array($query_random)) {
			$song_ID = $r['m_id'];
			$song_TITLE = $r['m_title'];
			$song_VIEWED = $r['m_viewed'];
			$user_ID = $row['m_poster'];
			$user_NAME =  m_get_data('USER',$user_ID);
			$song_TITLE1 = $song_TITLE;
			$user_URL	= url_link($user_ID,$user_NAME,'User');			
			$m_rate = $row['m_rating'];
			$m_rate_total = $row['m_rating_total'];
			if ($m_rate =='0') $current_star = 0;

			else $rater_rating = $m_rate / $m_rate_total;
			if ($rater_rating <= 0  ) $star = 0;
			if ($rater_rating >= 0.5) $star = 1;
    		if ($rater_rating >= 1) $star = 2;
			if ($rater_rating >= 1.5) $star = 3;
			if ($rater_rating >= 2) $star = 4;
			if ($rater_rating >= 2.5) $star = 5;
			if ($rater_rating >= 3) $star = 6;
			if ($rater_rating >= 3.5) $star = 7;
			if ($rater_rating >= 4) $star = 8;
			if ($rater_rating >= 4.5) $star = 9;
			if ($rater_rating >= 5) $star = 10;			
			$song_URL = url_link($song_ID,$song_TITLE,'nhac-san');
			$random_HTML .= "<li><p class='right'><span class='rate s_".$star."'><span><span><span><span><span></span></span></span></span></span></span><span class='add_pl'><a href='#' onclick='addToPlaylist($song_ID);return false;' title='Add to Playlist'></a></span></p><p class='title'><b>$i. </b><a href='$song_URL' title='$song_TITLE'>$song_TITLE1</a></p><p class='user'><p class='user'>Đăng bởi: <a href='$user_URL'>$user_NAME</a> | <a href='$cat_URL'>$cat_NAME</a> | Lượt nghe: $song_VIEWED</p></li>";
		
		}	
		
	}

include("templates/".$_SESSION['current_tpl']."/random_post.html");

}
?>
